package fr.afcepf.atod21.brigade.daoImpl;

import java.util.List;
import javax.persistence.EntityManager;
import fr.afcepf.atod21.brigade.dao.BasicDaoImpl;
import fr.afcepf.atod21.brigade.entity.Vehicule;

public class VehiculeDaoJpa extends BasicDaoImpl<Vehicule> {

	@Override
	public void persist(Vehicule anEntity) {
		EntityManager em = getEm();
		em.getTransaction().begin();
		em.persist(anEntity);
		em.getTransaction().commit();
	}

	@Override
	public Vehicule merge(Vehicule anEntity) {
		EntityManager em = getEm();
		em.getTransaction().begin();
		Vehicule Vehicule = em.merge(anEntity);
		em.getTransaction().commit();
		return Vehicule;
	}

	@Override
	public void remove(Vehicule anEntity) {
		EntityManager em = getEm();
		em.getTransaction().begin();
		em.remove(anEntity);
		em.getTransaction().commit();
	}

	@Override
	public Vehicule read(int id) {
		return (Vehicule) getEm().createQuery("select v from Vehicule v where v.idVehicule = :paramId").setParameter("paramId", id).getSingleResult();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Vehicule> findAll() {
		return getEm().createQuery("select v from Vehicule v").getResultList();
	}
}
